

/***
 * @Date            : 2024-12-29 23:14:43
 * @Author          : AnimateX(Baron)
 * @LastEditors     : AnimateX(Baron)
 * @LastEditTime    : 2024-12-29 23:15:03
 * @FilePath        : /include/frame_capture_manager.h
 * @CopyRight       : Copyright (c) 2025 AnimateX. All rights reserved.
 * @Description     :
 */
#include "frame_capture.h"


namespace rc {

    class FrameCaptureManager {
    public:
        using FramePairCallback = std::is_function<void(const Frame& rgb, const Frame& depth)>;

        explicit FrameCaptureManager(size_t rgbCapcity, size_t rgbImageSize, size_t irCapacity, size_t irImageSize)
            : rgbCapture_(std::make_unique<FrameCapture<uint8_t>>(rgbCapcity, rgbImageSize))
            , irCapture_(std::make_unique<FrameCapture<uint16_t>>(irCapacity, irImageSize)) {}

        void setFrameCallback(FramePairCallback cb) {
            frameCallback_ = cb;
        }

        bool initialize(CameraConfig rgbCfg, CameraConfig irCfg) {
            return rgbCapture_->initialize(rgbCfg) && irCapture_->initialize(irCfg);
        }

        bool start() {
            if (rgbCapture_ && irCapture_) {
                rgbCapture_->start();
                irCapture_->start();
                return true;
            }
            return false;
        }

        void stop() {
            if (irCapture_) {
                irCapture_->stop();
            }

            if (rgbCapture_) {
                rgbCapture_->stop();
            }
        }

        void run() {
            Frame rgbFrame, irFrame;
            while (!rgbCapture_) {

            }

        }

    private:
        FramePairCallback frameCallback_;

        std::unique_ptr<FrameCapture<uint8_t>> rgbCapture_;  // RGB stream
        std::unique_ptr<FrameCapture<uint16_t>> irCapture_;  // IR(origin uint16) stream

        bool matchTimestamps(const Frame& rgbFrame, const Frame& irFrame);
    };

}
